package com.ztesoft.ossup.report.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ztesoft.ossup.report.dao.JdbcTemplateDao;

@Service("sqlConfigService")
public class SqlConfigService extends BaseService{
	
	@Autowired
	JdbcTemplateDao jdbcTemplateDao;
	
	public List<Map<String,Object>> getTablesDefaultUser() throws Exception{
		String sql ="select TABLE_NAME from USER_TABLES ORDER BY TABLE_NAME";
//		String sql = "SELECT code as TABLE_NAME FROM REPORT ";
		List<Map<String,Object>> tableList = null;
		try {
			tableList = jdbcTemplateDao.getData(sql);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
		return tableList;
	}
	
	public List<Map<String,Object>> getViewsDefaultUser() throws Exception{
		String sql ="select VIEW_NAME from USER_VIEWS ORDER BY VIEW_NAME";
//		String sql = "SELECT code as VIEW_NAME FROM REPORT ";
		List<Map<String,Object>> tableList = null;
		try {
			tableList = jdbcTemplateDao.getData(sql);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
		return tableList;
	}
	
	public List<Map<String,Object>> getColsByTableName(String tableName) throws Exception{
		String sql ="select TABLE_NAME,COLUMN_NAME,DATA_TYPE from USER_TAB_COLS where TABLE_NAME = '" +tableName+"'";
		List<Map<String,Object>> colList = null;
		try {
			colList = jdbcTemplateDao.getData(sql);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
		return colList;
	}
	
	 
}
